<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
	xmlns:a="http://richfaces.org/a4j"
    xmlns:acabTravel="http://net.sareweb.acab.util/TravelUtil"
    template="/layout/template.xhtml">

<ui:define name="body">

	<h:form id="travelSearch" styleClass="edit">

        <rich:simpleTogglePanel label="Travel Search Filter" switchType="ajax">

            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Name</ui:define>
                <h:inputText id="name" value="#{findTravelsBean.travel.name}"/>
            </s:decorate>



            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Match</ui:define>
                <h:selectOneRadio id="logic" value="#{findTravelsBean.restrictionLogicOperator}" styleClass="radio">
                    <f:selectItem itemLabel="All" itemValue="and"/>
                    <f:selectItem itemLabel="Any" itemValue="or"/>
                </h:selectOneRadio>
            </s:decorate>

        </rich:simpleTogglePanel>

        <div class="actionButtons">
            <h:commandButton id="search" value="Search" action="/acab/travel/FindTravels.xhtml"/>
            <s:button id="reset" value="Reset" includePageParams="false"/>
        </div>

    </h:form>


	<rich:panel>
        <f:facet name="header">Travel Search Results (#{empty findTravelsBean.resultList ? 0 : (findTravelsBean.paginated ? findTravelsBean.resultCount : findTravelsBean.resultList.size)})</f:facet>
    <div class="results" id="findTravelsBean">

    <h:outputText value="The travel search returned no results."
               rendered="#{empty findTravelsBean.resultList}"/>

    <rich:dataTable id="findTravelsBean"
                var="_travel"
              value="#{findTravelsBean.resultList}"
           rendered="#{not empty findTravelsBean.resultList}">
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="Name"/>
                    <ui:param name="propertyPath" value="travel.name"/>
                </ui:include>
            </f:facet>

            <h:form>		
      			<s:link 
					value="#{_travel.name}"
					view="/acab/travel/TravelDetails.xhtml" 
					action="#{travelDetailsBean.selectTravelAction}" >
					<f:param name="idTravel" value="#{_travel.idTravel}"/>
				</s:link>
			</h:form>
			
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="User"/>
                    <ui:param name="propertyPath" value="travel.user.idUser"/>
                </ui:include>
            </f:facet>

            <s:div styleClass="acab_user_name">
        		<s:graphicImage value="#{avatarManager.getUsersAvatarByType(_travel.user, 'SMALL')}" rendered="#{avatarManager.getUsersAvatarByType(_travel.user.idUser, 'SMALL')!= null}" fileName="#{_travel.user.idUser}"  height="22"/>
        		<s:graphicImage value="/img/icons/no_avatar.jpg" rendered="#{avatarManager.getUsersAvatarByType(_travel.user.idUser, 'SMALL')== null}" fileName="default"  height="22"/>
        		<br/>
        		<h:outputText value="#{_travel.user.login}"/>
        	</s:div>

        </h:column>
		
		<h:column>
            <f:facet name="header">From</f:facet>
            <h:outputText value="#{_travel.countryByFromCountry.name  + ' ' + _travel.stateByFromState.name + ' ' + _travel.cityByFromCity.name}" rendered="#{_travel.cityByFromCity != null}"/>
        </h:column>
                
        <h:column>
            <f:facet name="header">To</f:facet>
            <h:outputText value="#{_travel.countryByToCountry.name + ' ' + _travel.stateByToState.name + ' ' + _travel.cityByToCity.name}" rendered="#{_travel.cityByToCity != null}"/>
        </h:column>
        
        
        
        
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="From lat"/>
                    <ui:param name="propertyPath" value="travel.fromLat"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_travel.fromLat}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="From lon"/>
                    <ui:param name="propertyPath" value="travel.fromLon"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_travel.fromLon}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="To lat"/>
                    <ui:param name="propertyPath" value="travel.toLat"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_travel.toLat}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="To lon"/>
                    <ui:param name="propertyPath" value="travel.toLon"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_travel.toLon}"/>
        </h:column>
        
        
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="Distance"/>
                    <ui:param name="propertyPath" value="travel.distance"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_travel.distance}"/>
        </h:column>
        
        

        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="Calculated rate"/>
                    <ui:param name="propertyPath" value="travel.calculatedRate"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_travel.calculatedRate}"/>
        </h:column>
        
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="Create date"/>
                    <ui:param name="propertyPath" value="travel.createDate"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_travel.createDate}">
                <s:convertDateTime type="date" dateStyle="short"/>
            </h:outputText>
        </h:column>
        
        
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{findTravelsBean}"/>
                    <ui:param name="propertyLabel" value="Begin date"/>
                    <ui:param name="propertyPath" value="travel.beginDate"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_travel.beginDate}">
                <s:convertDateTime type="date" dateStyle="short"/>
            </h:outputText>
            <h:outputText value="#{' to '}" rendered="#{!_travel.singleDay}"/>
            <h:outputText value="#{_travel.endDate==null and !_travel.singleDay ? '...' : _travel.endDate}">
                <s:convertDateTime type="date" dateStyle="short"/>
            </h:outputText>
        </h:column>
        
        <h:column>
            <f:facet name="header">Days</f:facet>
            <h:outputText value="MON," rendered="#{_travel.monday}"/>
            <h:outputText value="TUE," rendered="#{_travel.tuesday}"/>
            <h:outputText value="WED," rendered="#{_travel.wednesday}"/>
            <h:outputText value="THU," rendered="#{_travel.thursday}"/>
            <h:outputText value="FRI," rendered="#{_travel.friday}"/>
            <h:outputText value="SAT," rendered="#{_travel.saturday}"/>
            <h:outputText value="SUN," rendered="#{_travel.sunday}"/>       
        </h:column>

        
        <h:column>
            <f:facet name="header">Seats</f:facet>
            	<h:outputText value="#{travelManager.getFreeSeatAmount(_travel)}" rendered="#{_travel.seats != null}" />
            	<h:outputText value="/" rendered="#{_travel.seats != null}" />
            	<h:outputText value="#{_travel.seats.size}" rendered="#{_travel.seats != null}" />
        </h:column>
        
        <h:column rendered="#{identity.loggedIn}">
            <f:facet name="header"></f:facet>
    		<a:form rendered="#{!_travel.user.login.equals(identity.user.login) and dialogManager.findByTravelOtherUser(_travel.idTravel, identity.user.idUser)==null}">
    
    			<a:commandLink  reRender="panel"
								oncomplete="Richfaces.showModalPanel('panel', {})">
					<a:actionparam name="travId" value="#{_travel.idTravel}"
									assignTo="#{findTravelsBean.toTravel}" />
					<s:graphicImage value="/img/icons/conv_green.gif" height="22"/>
				</a:commandLink>
 			</a:form>
 			
 			<s:link view="/acab/travel/InterestingTravels.xhtml" rendered="#{!_travel.user.login.equals(identity.user.login) and dialogManager.findByTravelOtherUser(_travel.idTravel, identity.user.idUser)!=null}">
 			<s:graphicImage value="/img/icons/conv_red.gif" height="22" />
            </s:link>
        </h:column>
        
    </rich:dataTable>

    </div>
    </rich:panel>
    
    
 <!-- The modal panel -->   
<rich:modalPanel id="panel" width="350" height="200">
	<f:facet name="header">
		<h:panelGroup>
			<h:outputText value="Modal Panel"></h:outputText>
		</h:panelGroup>
	</f:facet>
	<f:facet name="controls">
		<h:panelGroup>
			<h:graphicImage value="/images/modal/close.png" styleClass="hidelink" id="hidelink"/>
			<rich:componentControl for="panel" attachTo="hidelink" operation="hide" event="onclick"/>
		</h:panelGroup>
	</f:facet>
	<h:outputText value="If you are interested in this travel, you can write a message to the owner. Who knows, you may be traveling soon toghether. :D"></h:outputText>
	<br/>
	<h:outputText value="If you start a communication with the owner, you will add this travel to you list...."></h:outputText>
	<br/>
	
	<h:form>
		<h:inputTextarea  id="newMsg" value="#{findTravelsBean.newMessage}" rows="5" cols="100"/>
		<h:inputHidden  id="toTravel" value="#{findTravelsBean.toTravel}"/>
		<div class="actionButtons">
       		<h:commandButton id="write"
                       value="Write"
                      action="#{findTravelsBean.writeMsgAction}" actionListener="#{findTravelsBean.writeMsgActionListener}"/>
		</div>
	</h:form>
 </rich:modalPanel>
    
    
    
    
    
    
    
    
        
        
</ui:define>
</ui:composition>